﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EarTag.API.Mediator.MediatorCommand.MarkCommand;
using S.EarTag.Read.API.Application.MediatorCommand.MarkCommand;
using S.EarTag.Read.API.Application.MediatorCommandHandler.MarkCommandHandler;
using S.EarTag.Read.API.Mediator.MediatorCommand.MarkCommand;
using SqlSugarTests.WebAPI.Model;

namespace S.EarTag.Read.API.Controllers
{
    /// <summary>
    /// 羊只戴标 — 归光阳
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MarkController : ControllerBase
    {
        private readonly IMediator _mediator;
        public MarkController(IMediator mediator)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 根据电子耳号进行去重查询
        /// </summary>
        /// <param name="EIITag"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMarkEITag(string? EIITag)
        {
            MarkRepeatCommand command = new MarkRepeatCommand();
            command.EITag = EIITag;
            var list = await _mediator.Send(command);
            return Ok(list);
        }
        /// <summary>
        /// 根据ids批量查询
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetMarkIds(string ids)
        {
            MarkGetidsCommand command = new MarkGetidsCommand();
            command.ids= ids;
            var list=await _mediator.Send(command);
            return Ok(list);
        }
        /// <summary>
        /// 查询全部未使用的耳标
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetAllState()
        {
            MarkGetAllCommand command = new MarkGetAllCommand();
            var list=await _mediator.Send(command); 
            return Ok(list);
        }
        /// <summary>
        /// 根据Id查询戴标数据—反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetByIdMark(int id)
        {
            MarkByIdCommand command = new MarkByIdCommand();
            command.MarkId = id;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 多条件查询+分页显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="EarTag"></param>
        /// <param name="EITag"></param>
        /// <param name="NewEITag"></param>
        /// <param name="WearId"></param>
        /// <param name="MarkState"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetMarkListpage(int pageIndex, int pageSize, string? EarTag, string? NewEITag, string? EITag, int WearId, string? MarkState)
        {
            
            MarkListPageCommand command = new MarkListPageCommand();
            command.pageIndex= pageIndex;
            command.pageSize= pageSize;
            command.EarTag = EarTag;
            command.NewEITag = NewEITag;
            command.EITag = EITag;
            command.WearId = WearId;
            command.MarkState = MarkState;
            var list=await _mediator.Send(command);
            return Ok(list);
        }
        /// <summary>
        /// 查询电子耳标下拉框
        /// </summary>
        /// <param name="MarkId"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetMarkList(int MarkId)
        {
            MarkSeachStateCommand command= new MarkSeachStateCommand();
            command.MarkId= MarkId;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据可视耳号修改状态
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetEarTagUpdState(string? EarTag)
        {
            MarkSeachStateEarTagCommand command = new MarkSeachStateEarTagCommand();
            command.EarTag= EarTag;
            var list = await _mediator.Send(command);
            return Ok(list);
        }

    }
}
